package com.heimali.sf.wraper;

import java.net.URI;
import java.net.URISyntaxException;

import com.heimali.sf.config.Constants;
import com.heimali.sf.http.JsonParser;
import com.heimali.sf.models.UpdateInfo;

public class UpdateWraper extends BaseWraper {
	public UpdateWraper(URI uri, Callback callback) {
		super(uri, callback);
	}
	
	public UpdateWraper(Callback callback) {
		super();
		try {
			this.uri = new URI(Constants.UPDATE_URL);
			this.callback = callback;
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	protected void onExecute(String result) {
		try {
			UpdateInfo info = JsonParser.updateInfoParser(result);
			if (info == null) {
				callback.onFail(Constants.E_SERVER_BUSY, null);
				return;
			}

			callback.onSuccess(info);

		} catch (Exception e) {
			callback.onFail(Constants.E_UNKNOWN_ERROR, e.getMessage());
		}
	}

}
